<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>精选板块</title>
		<link href="css/text.css" rel="stylesheet" type="text/css" />
		<style type="text/css">									
			.fixedBox{
				border: 1px solid #070707;
				white-space: nowrap;
				width:60%;
				height:72%; 
				left:300px;
				top:5px;							
				overflow:auto;
				margin-top:5px;
				margin-left:0px;
				margin-right:5px;
				padding-left:0px;
				padding-right:0px;
			}

			.fixedBox::-webkit-scrollbar {
				width: 12px;     
				height: 12px;				
			}			
			p {margin-top:0px;margin-bottom:5px}				
			
			table{ 
				border-collapse:collapse; 
				text-align:center;				
			}
			td,th{
				border:1px solid #696969;
				color:#E1FFFF;  <!-- 表头文字颜色 -->
			}						
			td a:link{
				color:#E1FFFF;  <!-- 列表文字颜色 -->
			}
		</style>		
	</head>
	<body>		
		<div id="towrites" style="position:relative;float:left;padding-top:0px;margin-top:-15px;"> 
			<div id="bar" style="margin:-5px"></div>
			<div id="towrite"  class="fixedBox" style="position:relative; float:left;border:none;">
				
			</div> 

			<div id="towritea" class="fixedBox" style="position:relative; float:left;border:none">
				<div id="towriter" style="position:relative; float:left;"></div>
			</div>
		</div>
		
		<script type="text/javascript" src="js/json2html.js"></script>
		<script type="text/javascript" src="js/jquery.min.js"></script>
		<script type="text/javascript" src="DatePicker/WdatePicker.js"> </script> 
		<script>

			// //板块跟随移动
			window.addEventListener('scroll', function() {
				var follower = document.getElementById('towrite');
				var scrollTop = window.scrollY; // 获取滚动条的垂直位置
			
				// 设置follower的top值，根据滚动位置变化
				follower.style.top = scrollTop +5+ 'px';

				// if(scrollTop >10 ){
				// 	// 设置follower的top值，根据滚动位置变化
				// 	follower.style.top = scrollTop  -2+ 'px';
				// } else{
				// 	follower.style.top = scrollTop -0 + 'px';
				// }
			});

			//排序算法
			function sortTable(c) {
				let table, rows, switching, i, x, y, shouldSwitch;
				table = document.getElementById("myTable");
				switching = true;
				while (switching) {
					switching = false;
					rows = table.rows;
					for (i = 1; i < (rows.length - 1); i++) {
					shouldSwitch = false;
					x = rows[i].getElementsByTagName("td")[c];
					y = rows[i + 1].getElementsByTagName("td")[c];
					if (Number(x.innerHTML) > Number(y.innerHTML)) {
						// 如果列是数字，则转换为数字比较
						shouldSwitch = true;
						break;
					}
					}
					if (shouldSwitch) {
					rows[i].parentNode.insertBefore(rows[i + 1], rows[i]);
					switching = true;
					}
				}
				}
										
			var conditionMet = false;
			// 自动刷新 页面 按钮
			function refreshPage() {

				var diva = document.getElementById("towrite");
				var sx=diva.getElementsByTagName("a")[2];
				var zdsx=diva.getElementsByTagName("a")[3]; 
				

				if(zdsx.innerHTML=="自动刷新"){
					sx.onclick = function(event) {
						event.preventDefault();
					}; 
					zdsx.innerHTML="停止刷新";
					zdsx.style.color = "#FF0000";
					sx.style.color = "#696969";
					conditionMet = true;

					(function autoRefresh() {
						//changeStyle();
						getSource();
						var sx=diva.getElementsByTagName("a")[2];
						var zdsx=diva.getElementsByTagName("a")[3];
						sx.onclick = function(event) {
							event.preventDefault();
						}; 
						zdsx.innerHTML="停止刷新";
						zdsx.style.color = "#FF0000";
						sx.style.color = "#696969";
						setTimeout(function() { 
							if (conditionMet) {
								autoRefresh(); // 如果条件未满足，继续自动刷新
							}
							}, 10*1000);
						})();

				}else{ 
					
					conditionMet = false;
					sx.onclick = getSource();
					zdsx.innerHTML="自动刷新";
					zdsx.style.color = "#FF8C00";
					sx.style.color = "#FF8C00";
				} 
			}

			var brcolor = $(".fixedBox").css("border");
			var bkcolor = $("body").css("backgroundColor");			
			var thcolor = "";
			var tdcolor = "";			
			var dt = "";
			var tt = "";
			var gt = "";
			var k = "0";	 
			window.onload = function() {
				var day = new Date();
				gt = day.getTime();		
				mymonth = day.getMonth()+1;
				myday = day.getDate();
				if(mymonth >= 10){mymonth = mymonth;}else{mymonth = "0" + mymonth;}
				if(myday >= 10){myday = myday;}else{myday = "0" + myday;}
				tt = day.getFullYear() + "-" + mymonth + "-" + myday;	
				dt = tt;
				changeStyle();
				getSource();	
				
			}
			
			function changeStyle() {
				var obj = document.getElementById("towrites");	
				//obj.style.border="1px solid #fff";
				obj.style.left= "0px"; 				
				obj.style.width= "99%";  // 196%  8列 ； 98% 4列
				obj.style.height= "80%";	//自适应的话，左栏 不跟随 很难操作；  所以固定大小好一些；  80% 自适应挺好，   880px 也很好	
				obj.style.fontSize="5px";	
				
				var obj1 = document.getElementById("towrite");
				obj1.style.border="1px solid #696969";				
				obj1.style.left= "0px"; 				
				obj1.style.width= "288px";	//15% 4列 ；
				obj1.style.height= "100%";

				var obj2 = document.getElementById("towritea");	
				obj2.style.border="1px solid #696969";				
				obj2.style.left= "0px"; 				
				obj2.style.width= "75%";	 //1560px   75%
				obj2.style.height= "100%";	
				
				var obj3 = document.getElementById("towriter");	
				obj3.style.border= "none";
				obj3.style.left= "0px"; 
				obj3.style.width= "98%";
				obj3.style.height= "96%";	
			}						
						
			function keepTwoDecimal(num) {  
               var result = parseFloat(num);  
               if (isNaN(result)) {  
                   //alert('传递参数错误，请检查！');  
                   return false;  
               }  
               result = Math.round(num * 100) / 100;  
               return result;  
			};			
			
			Date.prototype.Format = function (fmt) {
				var o = {
				"M+": this.getMonth() + 1, //月份
				"d+": this.getDate(), //日
				"h+": this.getHours(), //小时
				"m+": this.getMinutes(), //分
				"s+": this.getSeconds(), //秒
				"q+": Math.floor((this.getMonth() + 3) / 3), //季度
				"S": this.getMilliseconds() //毫秒
				};
				if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
				for (var k in o)
				if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
				return fmt;
			};
									
			function cDayFunc(dp) { 
				var date = dp.cal.getNewDateStr();            
				BookingRmk(date);//调用其它函数并带上参数                
			}
			
			function UnUnicode(str) {
				return unescape(str.replace(/\\/g, "%"));
			}
			
			window.onresize = function() {
				<!-- var h =  document.getElementById('towrite').offsetHeight ;				 -->
				<!-- var div = document.getElementById('towritea'); -->
				<!-- div.style.height = h - 20 + 'px';	 -->
			}
			
			function BookingRmk(date){         
				tt = date;
				var date1 = new Date(tt);
				var date2 = new Date(dt);						
				k = 0;
				if(date1.getTime() < date2.getTime()){			
					k = 1;					
					tradeday();					
				}
				
				getSource();						
			}
			
			function prev(){  //前一天
				pn = -1;
				var day = new Date(tt);	
				day.setTime(day.getTime() - 24*60*60*1000);	
				tt = day.Format("yyyy-MM-dd");
				BookingRmk(tt);				
			}
			
			function next(){  //后一天 				
				pn = 1;
				var day = new Date(tt);	
				day.setTime(day.getTime() + 24*60*60*1000);	
				tt = day.Format("yyyy-MM-dd");
				BookingRmk(tt);							
			}
			
			var pn = -1;
			function tradeday() {  //判断最后交易日
				var day = new Date(tt);							
				for (i = 1; i < 100; i++){	//节假日																										
					if(i > 1){
						day.setTime(day.getTime() + pn*24*60*60*1000);							
					}	
					tt = day.Format("yyyy-MM-dd");
					//alert(tt);
					if(tt == dt){	
						k = 0;
						getSource();
						break;
					}
					//var url = "http://127.0.0.1:8881/w1/api/index.php?Order=1&a=RealRankingInfo&st=30&apiv=w26&Type=1&c=ZhiShuRanking&PhoneOSNew=1&ZSType=7&Date=" + tt; 			
					var url = "https://apphis.longhuvip.com/w1/api/index.php?a=RealRankingInfo&apiv=w33&c=ZhiShuRanking&ZSType=5&st=50&Type=1&Order=1&VerSion=5.13.0.2&PhoneOSNew=1&DeviceID=ffffffff-63da-215a-a6f3-00000003a92d&Date=" + tt; 		
					
					var res = [];
					$.ajax({
						type: "get",
						url: url,
						dataType: "json",
						async : false,
						cache:false,
						timeout:3000,						
						success: function(data) {							
							res = data.list;							
						}
					});
					if(res.length != 0){						
						break;
					}
				}
			}	
			

			//精品板块 列表， 左栏的数据
			function getSource() {				
				var diva = document.getElementById("bar");
				var sx = "<a style='left:0px; color:#FF8C00' href='javascript:void(0)' onclick='getSource()'>" + "刷新" + "</a>"; 
				var zdsx = "<a style='left:0px; color:#FF8C00' href='javascript:void(0)' onclick='refreshPage()'>" + "自动刷新" + "</a>";

				//diva.innerHTML = '<font size="3">' + sx + zdsx+'</font>';
				
				var div = document.getElementById('towrite');																
				div.innerHTML = '<font size="2" style=color:#FFFF00;>日期 </font><input style="width:90px;" type="text" id="PriceDate" name="PriceDate" class="Wdate" onFocus="WdatePicker({ onpicking: cDayFunc})" />';		
				
				var back = '<a href="javascript:prev();"  style="padding-left:0px;font-size:10px;color:#fff;">←</a>';				
				var forward = '<a href="javascript:next();"  style="font-size:10px;color:#fff;">→</a>';
				div.innerHTML += back + forward ; 
				
				div.innerHTML += '<font size="2">' + sx + zdsx+'</font>';
				
				//var url1 = "http://127.0.0.1:8880/w1/api/index.php?Order=1&a=RealRankingInfo&st=30&apiv=w21&Type=1&c=ZhiShuRanking&PhoneOSNew=1&ZSType=7"; 
				//var url2 = "http://127.0.0.1:8881/w1/api/index.php?Order=1&a=RealRankingInfo&st=30&apiv=w26&Type=1&c=ZhiShuRanking&PhoneOSNew=1&ZSType=7&Date=" + tt; 			
				var url1 = "https://apphq.longhuvip.com/w1/api/index.php?Order=1&a=RealRankingInfo&st=50&apiv=w21&Type=1&c=ZhiShuRanking&PhoneOSNew=1&ZSType=7&"; 
				var url2 = "https://apphis.longhuvip.com/w1/api/index.php?Order=1&st=50&a=RealRankingInfo&c=ZhiShuRanking&Index=0&apiv=w35&Type=1&ZSType=7&VerSion=5.13.0.2&PhoneOSNew=1&DeviceID=ffffffff-557f-8236-5073-0000026bf11c&Date=" + tt;
 		
				var url = url1;
				if(k == "1"){
					url = url2;
				}				
				
				var dd = [];	
				var res = [];
				$.ajax({
					type: "get",
					url: url,
					dataType: "json",
					async : false,
					cache:false,
					timeout:3000,					
					success: function(data) {
						//alert(JSON.stringify(data))						
						//document.write(JSON.stringify(data));							
						if(k == 0){
							tt = data.Day;							
							dt = tt;
						}
						//alert(dt)
						var n = 0;
						for (i = 0; i < data.list.length; i++){
							var code = data.list[i][0];
							var name = data.list[i][1];		
							var qd = data.list[i][2];
							var zf = data.list[i][3];					
							if(name.indexOf("ST") == -1){								
								n++;
								if(n ==44){
									break;
								}			
								
								//code  代码   name 名称 qd 强度 zf 涨幅
								res.push({"code":data.list[i][0],"name":data.list[i][1].toString().trim().substr(0,6),"qd":data.list[i][2],"zf":data.list[i][3]});
								//dd += code + "," + name + "},{";
								dd.push({code,name,qd,zf});
							}
						}						
					}
				});				
				//document.write(JSON.stringify(dd));

				
				//var json = JSON.parse(bks);	
				var json = res;	
				//创建table					
				var table = document.createElement("table");										
				var thead = document.createElement("thead");
				table.appendChild(thead);					
				var tr = document.createElement("tr");
				thead.appendChild(tr);					
					
				// 定表头
				for(var key in json[0]){  //表头
					key = key.replace('code','代码').replace('name','名称').replace('qd','强度').replace('zf','最高板');										
					var th = document.createElement("th");						
					th.innerHTML = key;						
					tr.appendChild(th);							
				}
									
				var tbody=document.createElement("tbody");					
				table.appendChild(tbody);
				
				//遍历json
				for(var i = 0; i < json.length; i++){					
					var tr = document.createElement("tr");
					var p = 1						
					for(var key in json[i]){ //行元素遍历						
						var td = document.createElement("td");														
						var rc = json[i][key];
						if(p == 1){  //代码列
							dm = rc;
						}		
						if(p == 4){
							rc = keepTwoDecimal(rc);
						}
						//td.innerHTML = rc
						td.innerHTML = "<a href='javascript:void(0)' id='" + p + "' onclick='changeCss(\"towrite" + dm + "\");Focus(\"towrite" + (i + 1) + "\")'>" + rc + "</a>";
						if(key=="zf"){
							td.width=90;
						}
						if(key=="name"){
							td.width=110;
						}
						
						tr.appendChild(td);
						tr.id = "towrite" + dm;
						p++;							
					}
					$("table tr").find("td:eq(0)")
					tbody.appendChild(tr);											
				}									
				div.appendChild(table);
				//table.id = id;				
				changeTable(table,"0");		//隐藏某列					
				AddTableCell(table);   //添加序号列
				hovera(); 

									
				//延迟显示板块个股				
				setTimeout(loop, 100);
				var m = 0;
				function loop(){															
					var code = dd[m]["code"];  // 板块代码
					var name = dd[m]["name"];  // 板块名称
					var qd = dd[m]["qd"];  // 板块名称
					var zf = dd[m]["zf"];  // 板块名称
					m++;						

					//bkgg(m,code,name);
					//bkgg(编号,代码,名字,强度,涨幅);
					bkgg(m,code,name,qd,zf);
					if( m < dd.length){
						setTimeout(loop, 1);
					}			
				};					
				document.getElementById("PriceDate").value = tt;
				
				//初始化高亮
				$("#towritea").scrollLeft (0); 
				var tlist = document.getElementById("towriter").getElementsByTagName('div');
				for(var i = 0; i < tlist.length; i++){														
					tlist[i].style.border = brcolor;					
				}	
			} 
			
			//动态添加列
			function AddTableCell(table){
				var Table = table			   
				var rowLength = Table.rows.length;  //行數量
				//var cellLength=Table.rows[0].cells.length; //查找單元格数量
				for(var i = 0; i < rowLength; i++){					
					var NewCell = Table.rows[i].insertCell(0);
					if(i == 0){
						NewCell.innerHTML = "序号";
					}else{
						NewCell.innerHTML = i;
					}					
				}				
			}

			var iiiid = -1;

			function Focus(id){  //移动		
				
				
				var diva = document.getElementById("towrite");
				var sx=diva.getElementsByTagName("a")[2];
				var zdsx=diva.getElementsByTagName("a")[3]; 

				//如果打开了自动刷新，先停止
				if(zdsx.innerHTML=="停止刷新"){
					conditionMet = false;
					sx.onclick = getSource();
					zdsx.innerHTML="自动刷新";
					zdsx.style.color = "#FF8C00";
					sx.style.color = "#FF8C00";

				} 

				//alert(brcolor)	
				var tlist = document.getElementById("towriter").getElementsByTagName('div');
				/// 后加的内容
				if(iiiid!=-1)
				{
					tlist[iiiid].style.border = "1px solid #000000";	
					//iiiid = id;
				} 

				if (iiiid!=id) {
					iiiid = id;

				} 
				
				//原来的代码
				// for(var i = 0; i < tlist.length; i++){	 
				// 	tlist[i].style.border = brcolor;	 
				// }

				//滚动到指定位置
				document.getElementById(id).scrollIntoView({
					behavior: 'smooth' // 可选，平滑滚动
				});	

				var div = document.getElementById(id);		

				// // //todo:20240413	 待修改 #FFA500 橙色  ； #FF0000 红色
				div.style.border = "1px solid #FF0000";

				//var x = div.offsetLeft;
				//$("#towritea").scrollLeft (x);				
			}
			
			var rid = "";
			function changeCss(id){	
				rid = id;
				////todo
				var tlist = document.getElementById("towrite").getElementsByTagName('tr');					
				for(var i = 0; i < tlist.length; i++){														
					tlist[i].style.backgroundColor = brcolor;					
				}				
				var tr = document.getElementById(id);				
				tr.style.backgroundColor = "#2F4F4F";						
				tr.style.backgroundColor = "#2F4F4F";						
			}
			
			function hovera(){  //鼠标经过					
				//var rows = document.getElementsByTagName('tr');
				var rows = document.getElementById("towrite").getElementsByTagName('tr');
				for(var i=0;i<rows.length;i++){
					rows[i].onmouseover=function(){							
						if(this.id != ""){  //过滤表头
							this.style.background="#800000";
						}
					}
					rows[i].onmouseout=function(){
						if(this.id != ""){  //过滤表头						
							if(rid == this.id){
								this.style.background ="#2F4F4F";							
							}else{
								this.style.background = bkcolor;						
							}							
						}						
					}					
				}
			}
						
			//成分股 列表
			function bkgg(n,code,name,qiangdu,zhangfu){	
				var bkcode = code;
				var newDiv = document.getElementById("towrite" + n);
				if(!newDiv){
					//添加分类Div				
					var newDiv = document.createElement("div");
					newDiv.id = "towrite" + n;
					newDiv.className = "fixedBox";
					newDiv.style.left = "0px"; 	
					newDiv.style.width = "333px";
					newDiv.style.position = "relative"; 
					newDiv.style.float = "left"; 
					newDiv.style.fontSize="5px"; //成分股 字体大小   todo
					newDiv.style.whiteSpace = "nowrap";	
					document.getElementById("towriter").appendChild(newDiv);
				}	 
				var url1 = "https://apphq.longhuvip.com/w1/api/index.php?Order=1&st=30&a=ZhiShuStockList_W8&c=ZhiShuRanking&PhoneOSNew=1&old=1&apiv=w21&Type=6&DeviceID=6575961a-b25b-3831-aa2b-4a373b51b256&VerSion=5.12.0.0&PlateID=" + code;							
				var url2 = "https://apphis.longhuvip.com/w1/api/index.php?st=30&Index=0&old=1&Order=1&a=ZhiShuStockList_W8&apiv=w26&Type=6&c=ZhiShuRanking&PhoneOSNew=1&DeviceID=6575961a-b25b-3831-aa2b-4a373b51b256&VerSion=5.12.0.0&PlateID=" + code + "&Date=" + tt;		
			//var url1 = "https://apphq.longhuvip.com/w1/api/index.php?Order=" + order + "&st=30&a=ZhiShuStockList_W8&c=ZhiShuRanking&PhoneOSNew=1&old=" + old + "&apiv=w21&Type=" + type + "&DeviceID=6575961a-b25b-3831-aa2b-4a373b51b256&VerSion=5.12.0.0&PlateID=" + bdm; 								
				//var url2 = "https://apphis.longhuvip.com/w1/api/index.php?st=30&Index=0&old=" + old + "&Order=" + order + "&a=ZhiShuStockList_W8&apiv=w26&Type=" + type + "&c=ZhiShuRanking&PhoneOSNew=1&DeviceID=6575961a-b25b-3831-aa2b-4a373b51b256&VerSion=5.12.0.0&PlateID=" + bdm + "&Date=" + tt;		
				var url = url1;
				if(k == "1"){
					url = url2;
				}	
								
				var res = [];
				//涨停数
				var num = 0;
				var zbNum = 0;
				var totalNum = 0;
				var zgNum=0;	
				var zgName='';	
				var zgCode='';
				$.ajax({
					type: "get",
					url: url,
					dataType: "json",
					async : false,
					cache:false,
					timeout:3000,					
					success: function(data) {
						//alert(JSON.stringify(data))						
						//document.write(JSON.stringify(data));		
																
						for (i = 0; i < data.list.length; i++){
							var aa = data.list[i];
							var code = aa[0].trim();
							//if(code.substr(0,1)=="3"){
								//代码 ，名字，涨幅，连扳，板块，封单, 是否炸板，最高板数

								// 获取原始字符串
								var originalString = aa[23].trim();
								
								// 使用正则表达式匹配开头的数字
								var regex = /^\d+/;
								var match = originalString.match(regex);
								
								// 提取的数字，如果存在的话
								var extractedNumber = match ? match[0] : '';
								var nn = parseInt(extractedNumber);
								if(nn> 0){
									if(zgNum<nn){
										zgNum=extractedNumber;
										zgName=aa[1].trim();
										zgCode=code;
									}
								}

								res.push({"code":code,"name":aa[1].trim(),"zf":aa[6],"lb":aa[23],"bk":aa[4].substr(0,11),"fd":aa[28],"zb":aa[24].toString().trim(),"zg":extractedNumber});
								if(aa[28]>0){
									num ++;
								} 

								if(aa[24].toString().trim()=="破板"){
									zbNum ++;
								}
							//}							
						}											
					}
				});	
				
				totalNum =num + zbNum;

				var zblv=100*zbNum/totalNum;
				
				//成分股 标题		
				var titles =  n+"、"+name+" "+qiangdu+" 涨幅:"+zhangfu.toFixed(2)+"% 炸板率:"+zblv.toFixed(0)+"% 涨停数:"+num;
				var tlistTb=document.getElementById("towrite"+bkcode);	 
				tlistTb.getElementsByTagName("a")[1].innerHTML = tlistTb.getElementsByTagName("a")[1].innerHTML + " ["+num +"]"

				var zgb = zgName + "["+zgNum +"]";

				//href=http://www.treeid/code_

				if('[0]'!=zgb){
					tlistTb.getElementsByTagName("a")[3].innerHTML = zgb;
					tlistTb.getElementsByTagName("a")[3].href = "http://www.treeid/code_"+zgCode;
					if(zgNum>6){
						tlistTb.getElementsByTagName("a")[3].style.color = "#FF0000";
					}
				}else{
					tlistTb.getElementsByTagName("a")[3].innerHTML = "";
				}

				
				if(zhangfu<0)
				{  
					if(num<5){
						newDiv.innerHTML = "<font size='2' style=color:#00ff00;>" + titles+ "</font>"; 
					}else{
						newDiv.innerHTML = "<font size='2' style=color:#FFFF00;>" + titles+ "</font>"; 
					} 
					if(num>7){
						newDiv.innerHTML = "<font size='2' style=color:#FF0000;>" + titles+ "</font>";
						tlistTb.getElementsByTagName("a")[1].style.color = "#FF0000"; 
					}
				}else{
					if(num>7){
						newDiv.innerHTML = "<font size='2' style=color:#FF0000;>" + titles+ "</font>";
						tlistTb.getElementsByTagName("a")[1].style.color = "#FF0000"; 
					}else{
						newDiv.innerHTML = "<font size='2' style=color:#FFFF00;>" + titles+ "</font>"; 
					} 
				} 
				//document.write(data);
				
				//var json = JSON.parse(data);
				var json = res;	
				//创建table					
				var table=document.createElement("table");										
				var thead=document.createElement("thead");
				table.appendChild(thead);					
				var tr=document.createElement("tr");
				thead.appendChild(tr);					
				
				var m = 0;
				var v = 0;
				var b = 0;
				var gl = "涨幅";  //高亮

				//制定 成分列表 表头
				for(var key in json[0]){  			
					if(key=="fd"||key=="zb"||key=="zg")		{
						continue;
					}	 

					key = key.replace('code','代码').replace('name','名称').replace('zf','涨幅%').replace('lb','连板').replace('bk','板块');
					var th=document.createElement("th");				
					th.innerHTML=key;	
					th.style.color = "#87CEFA";  
					tr.appendChild(th);	 
 
					m++;
				}
									
				var tbody=document.createElement("tbody");					
				table.appendChild(tbody);
				
				//遍历json
				//填充 成分个股
				for(var i = 0; i < json.length; i++){					
					var tr=document.createElement("tr");						
					var p = 1;	
					var dm = "";
					var mc = "";					
					for(var key in json[i]){ //行元素遍历			
						
						if(key=="fd"||key=="zb"||key=="zg"){
							continue;
						}
						
						var td=document.createElement("td");							
						
						var rc = json[i][key];

						//代码列
						if(p == 1){  
							dm = rc;
							tr.id = dm + "##" + code;
						}		
						
						if(key=="lb"){
							var zb = json[i]["zb"];
							if (zb=="破板"){
								rc = zb;  
							} 
						}


						td.innerHTML = "<a href=http://www.treeid/code_" + dm + " id='" + p + "'  onclick='changeTCss(\"" + newDiv.id + "\",\"" + tr.id + "\")'>" + rc + "</a>";

						if(key=="lb"){
							var zb = json[i]["zb"];
							if (zb=="破板"){ 
								td.getElementsByTagName("a")[0].style.color = "#00ff00"; //绿色
							} 
						}
							 
						// 300 688 689 301 变色
						if(dm.substr(0,2)=="30" || dm.substr(0,2)=="68"){
							tr.style.backgroundColor  = "#2F4F4F";
							//2F4F4F
						}	

						//有封单的时候  涨停 底色变红 色
						if(key=="zf"){
							var fd = json[i]["fd"];
							if (fd>0){
								td.style.backgroundColor = "#FF0000"; 
							}
							if(rc>11 && fd<=0){
								td.getElementsByTagName("a")[0].style.color = "#FF0000";
							}
						} 

						//2 -4 连扳 黄色
						var kkkk1 = /^[0-7]连板$/.test(rc.toString());

						//5 -8 连扳 红色
						var kkkk2 = /^[5-8]连板$/.test(rc.toString());

						//9 以上 连扳 红色
						var kkkk3 = /^[9]连板$/.test(rc.toString()) || /^[0-9]{2}连板$/.test(rc.toString());
						
						if(key=="lb" && kkkk1 ){
							td.getElementsByTagName("a")[0].style.color = "#FFFF00";
						}

						if(key=="lb" && kkkk2 ){
							td.getElementsByTagName("a")[0].style.color = "#FF1493";
						}

						if(key=="lb" && kkkk3 ){
							td.getElementsByTagName("a")[0].style.color = "#FF0000";
						}

						tr.appendChild(td);
						p++;
					}						
					tbody.appendChild(tr);
				}									
				newDiv.appendChild(table);
				table.id = code;					
				changeTable(table,"0");		//隐藏某列	
				
				makeSortable(table);			
				hover();				
			}
						
			//隐藏某列				
            function changeTable(table,ss) {	
				var trs = table.rows;
				ss = ss + '#';
				var aa = ss.split('#');
				for (var j = 0; j < aa.length; j++) {
					if(aa[j] != ""){
						for (var i = 0, len = trs.length; i < len; i++) {					
							var p = aa[j];
							var cell = trs[i].cells[p]; 
							cell.style.display = 'none';
						}
					}
				}					
			}
			
			var trid = "";
			function changeTCss(tid,id){				
				trid = id;
				var dm = id.split("##")[0];
				var bk = id.split("##")[1];
				var tlist = document.getElementById("towriter").getElementsByTagName("tr");					
				for(var i = 0; i < tlist.length; i++){
					var dms = tlist[i].id.split("##")[0];
					var bks = tlist[i].id.split("##")[1];					
					if(dms == dm){
						tlist[i].style.backgroundColor = "#800080";						
						if(bks != bk){
							var t = tlist[i].parentNode.parentNode.parentNode.id;  //td父节点tr id							
							$("#" + t).scrollTop (0);												
							var y = getTop(tlist[i]);  //纵坐标
							var div = document.getElementById(t);						
							if(y > div.clientHeight){						
								$("#" + t).scrollTop (y - 100);  //控制滚动条
							}
						}
					}else{
						if(dms.substr(0,2)=="30" || dms.substr(0,2)=="68"){					
							tlist[i].style.backgroundColor = "#2F4F4F"; //2F4F4。F
						}else{
							tlist[i].style.backgroundColor = bkcolor;
						}	 

						//tlist[i].style.backgroundColor = bkcolor;
					}					
				}				
				//var tr = document.getElementById(id);				
				//tr.style.backgroundColor = "#2F4F4F";						
			}
			
			//获取元素的纵坐标 
			function getTop(e){ 
				var offset=e.offsetTop; 
				if(e.offsetParent!=null) offset+=getTop(e.offsetParent);				
				return offset; 
			} 		
			
			var gcolor = "#8B008B";
			function hover(){  //鼠标经过					
				var rows = document.getElementById("towriter").getElementsByTagName('tr');
				for(var i=0;i<rows.length;i++){
					rows[i].onmouseover=function(){							
						if(this.id != ""){  //过滤表头
							this.style.background="#800000";
						}
					}
					rows[i].onmouseout=function(){
						if(this.id != ""){  //过滤表头						
							if(trid == this.id){
								this.style.background ="#800080";							
							}else{
								if(this.id.substr(0,2)=="30" || this.id.substr(0,2)=="68"){		 
									this.style.backgroundColor = "#2F4F4F";
								}else{
									this.style.backgroundColor = bkcolor;
								}	
								//this.style.background = bkcolor;						
							}							
						}						
					}					
				}
			}
			
			
			function makeSortable(table) {		
				var headers=table.getElementsByTagName("th");
				for(var i=0;i<headers.length;i++){				
					(function(n){
						var flag=false;
							
						headers[n].onclick=function(){											
							showCol(table,n);		//高亮
							var tbody=table.tBodies[0];
							var rows=tbody.getElementsByTagName("tr");
							rows=Array.prototype.slice.call(rows,0);

							//基于第n个<td>元素的值对行排序
							rows.sort(function(row1,row2){
								headtxt = headers[n].textContent;								
								var cell1=row1.getElementsByTagName("td")[n];//获得第n个单元格
								var cell2=row2.getElementsByTagName("td")[n];																
								var val1=cell1.textContent||cell1.innerText;//获得文本内容
								var val2=cell2.textContent||cell2.innerText;
								if(headtxt.indexOf("名称") != -1 || headtxt.indexOf("主力") != -1|| headtxt.indexOf("主题") != -1){
									val1 = val1;
									val2 = val2;
								}else if(headtxt.indexOf("连板") != -1){								
									val1 = val1.replace("昨日首板","-1").replace("首板","1").replace("连板","");
									if(val1.indexOf("天")>-1){
										val1 = val1.split("天")[0];
									}else if(val1.indexOf("昨")>-1){
										val1 = 0;
									}else if(val1 == ""){
										val1 = -2;
									}										
									val1 = parseFloat(val1);
								
									val2 = val2.replace("昨日首板","-1").replace("首板","1").replace("连板","");
									if(val2.indexOf("天")>-1){
										val2 = val2.split("天")[0];
									}else if(val2.indexOf("昨")>-1){
										val2 = 0;
									}else if(val2 == ""){
										val2 = -2;
									}									
									val2 = parseFloat(val2);
								}else{											
									if(val1.indexOf("万") != -1){
										val1 = parseFloat(val1)*10000;
									}else if(val1.indexOf("亿") != -1){
										val1 = parseFloat(val1)*100000000;
									}else{
										val1 = parseFloat(val1);
									}
									
									if(val2.indexOf("万") != -1){
										val2 = parseFloat(val2)*10000;
									}else if(val2.indexOf("亿") != -1){
										val2 = parseFloat(val2)*100000000;
									}else{
										val2 = parseFloat(val2);
									}
								}
								if(val1<val2){
									return -1;
								}else if(val1>val2){
									return 1;
								}else{
									return 0;
								}
							});
							if(flag){
								rows.reverse();
							}
							
							for(var i=0;i<rows.length;i++){
								tbody.appendChild(rows[i]);
							}

							flag=!flag;
						}
					}(i));
				}
			}
			
			function showCol(table,iCol){			
				var oTable = table;
				var id = oTable.id;
				for (i=0;i < oTable.rows.length; i++){										
					for (j=0;j < oTable.rows[0].cells.length; j++){
						//alert(oTable.rows[i].cells[3].innerText)
						oTable.rows[i].cells[j].style.color = thcolor;
						//if(oTable.id != "towrite6"){
							oTable.rows[i].cells[3].style.color = "#FFA500";
						//}						
					}
					oTable.rows[i].cells[iCol].style.color = "#FF6633";					
				}
				
				var otagsA = oTable.getElementsByTagName("a");  //a变色
				for (i = 0; i < otagsA.length; i++) {
					otagsA[i].style.color = tdcolor;
					if(otagsA[i].id == 4){
						otagsA[i].style.color = "#FFA500";
					}	
					if(otagsA[i].id == iCol + 1){
						otagsA[i].style.color = "#FF6633";
					}
				}				
			}
			
		</script>		
	</body>
</html>